package com.moviemetagetter.adapter;

import java.net.URLEncoder;
import java.util.List;

import com.moviemetagetter.http.HTTPHelper;
import com.moviemetagetter.model.Movie;
import com.moviemetagetter.xml.TagChimpXmlParser;

public class TagChimpAdapter {
	
	private static final String SEARCH_URL = "https://www.tagchimp.com/ape/search.php";
	private static final String TOKEN = "20497898364DAA2923EE2BA";

	public List<Movie> getTagData(String movieTitle){
		String xml = getXml(movieTitle);

		TagChimpXmlParser parser = new TagChimpXmlParser();
		return parser.parse(xml);
	}
	
	@SuppressWarnings("deprecation")
	private String getXml(String movieTitle){
		String url = SEARCH_URL + "?token=" + TOKEN + "&type=search&totalChapters=x&title=" + URLEncoder.encode(movieTitle);
		String result = HTTPHelper.get(url, null);
		return result;
	}
}
